#include "marcadorpais.h"
#include <QPainter>
#include <QGraphicsSceneMouseEvent>

MarcadorPais::MarcadorPais(QString nome_pais, Qt::GlobalColor color, QGraphicsItem* parent) : QGraphicsEllipseItem (parent)
{
    this->nome_pais = nome_pais;
    this->color = color;
    this->tropas_adicionadas = 0;
    this->numero_tropas = 0;
    this->setRect(0,0,20,20);
    this->update();
}

void MarcadorPais::paint(QPainter* painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    painter->setPen(Qt::NoPen);
    painter->setBrush(this->color);
    painter->drawEllipse(this->rect());

    if (this->color == Qt::white || this->color == Qt::yellow)
        painter->setPen(Qt::black);
    else
        painter->setPen(Qt::white);

    painter->drawText(0, 0, 20, 20, Qt::AlignCenter, QString::number(this->numero_tropas + this->tropas_adicionadas));
}

void MarcadorPais::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
    event->accept();
    emit this->marcadorClicado(this, event->button());
}
